#include <QTabWidget>
#include <QVBoxLayout>

#include <pluginui/manager/spi/StandardDialogContentPanelManager.h>

namespace antu
{
namespace plugin
{
namespace ui
{
StandardDialogContentPanelManager::StandardDialogContentPanelManager(QWidget* pContainerWidget)
    : AbstractPanelManager(),
      m_pContainerWidget(pContainerWidget)
{
}

void StandardDialogContentPanelManager::finalize()
{
    size_t count = this->m_oPanels.size();

    QVBoxLayout* pLayout = new QVBoxLayout;
	pLayout->setContentsMargins(0, 0, 0, 0);
    this->m_pContainerWidget->setLayout(pLayout);

    if (count == 1)
    {
        pLayout->addWidget(this->m_oPanels[0]->containerWidget());
        //this->m_pMainWindow->setCentralWidget(this->m_oPanels[0]->containerWidget());
    }
    else if (count > 1)
    {
        QTabWidget* pWidget = new QTabWidget(this->m_pContainerWidget);
        pWidget->setTabsClosable(false);
        auto iter = this->m_oPanels.begin();
        auto end = this->m_oPanels.end();
		pWidget->setContentsMargins(0, 0, 0, 0);

        for (; iter != end; iter++)
        {
            (*iter)->finalize();
            QWidget* pChildWidget = (*iter)->containerWidget();

            if (pChildWidget->windowIcon().isNull())
            {
                pWidget->addTab(pChildWidget, pChildWidget->windowTitle());
            }
            else
            {
                pWidget->addTab(pChildWidget, pChildWidget->windowIcon(), pChildWidget->windowTitle());
            }
        }
        pLayout->addWidget(pWidget);
    }
}

void StandardDialogContentPanelManager::createContainer(AbstractPanelContainer* /*pContainer*/,
                                                        Qt::DockWidgetArea /*area*/,
                                                        Qt::DockWidgetAreas /*allowedAreas*/,
                                                        QDockWidget::DockWidgetFeatures /*features*/)
{

}

}
}
}

